var geoHazardQueryForSketchQueryDlg=null;
var sketchQueryDlg =null;
var global_vector_layer =null;
	function onClickOneHazardForSketchQuery(tybh,name,zdType){
		var url = "queryYjdc3jbxxByTybh.shtml";
		var data = {
				startTime:"",
				endTime:"",
				tybh:tybh,
				biaoshi:zdType
		};
		global_sketch_geoCode = tybh;
		global_sketch_geoCodeType = zdType;
		$.post(url,data,initSketchQueryDlg);
	}
	
	function initSketchQueryDlg(res){
		if(global_vector_layer){
			map.removeLayer(global_vector_layer);
			global_vector_layer = null;
		}
		if(geoHazardQueryForSketchQueryDlg){
			//geoHazardQueryForSketchQueryDlg=null;
		}
		res = eval("("+res+")");
		var sketchQueryDlgHTML= '<div style="width:340px;height:200px;font-size:11px;font-family:微软雅黑;position:absolute;left:15px;top:40px;">'+
								'<label style="color: red;">请您选择应急调查的时间:</label><select style="width:150px;" id="chooseTime"></select>'+
								'</div>';
		sketchQueryDlg = $.dialog({
			title: '素描图',
			content: sketchQueryDlgHTML,
			dlgDivId: "sketchQueryDlgDiv",
			resize: false,
			max: false,
			left:"250px",
			top:'100px',
			width:'340px',
			height:'50px',
			min:onSketchQueryDlgMin,
			
			init:function(){
					$("#fanzaoDiv td").css("border","1px solid #D8DBE0");
					//初始化完毕，加载时间选择列表
					var optionStr = '<option selected="selected" value="">请选择调查时间</option>';
					
					for(var i = 0;i<res.length;i++){
						var time = res[i].yjdc01270;
						var year = Number(time.year)+1900;
						var month = (Number(time.month)+1)<10?"0"+(Number(time.month)+1):(Number(time.month)+1);
						var day = Number(time.date<10)?"0"+time.date:time.date;
						var hours = Number(time.hours<10)?"0"+time.hours:time.hours;
						var minutes = Number(time.minutes<10)?"0"+time.minutes:time.minutes;
						var seconds = Number(time.seconds<10)?"0"+time.seconds:time.seconds;
						var timeStr  = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
						optionStr = optionStr + '<option value="'+res[i].yjdc01270.time+'">'+timeStr+'</option>';
					}
					
					$("#chooseTime").html("");
					$("#chooseTime").change(queryAllFeaturesByTime);
					$("#chooseTime").append(optionStr);


					
					//$("#editInsertButton").click(editInsertClickFunction);
					///$("#geohazardBtn").click(onQueryGeoHazardFunction);
			},
			close:onSketchQueryDlgClose
		});
}

    function queryAllFeaturesByTime(){
    	if(global_vector_layer)
    	{
    		global_vector_layer.removeAllFeatures();
    		global_vector_layer =null;
    	}
    	global_features_add = new Array();
    	global_features_del = new Array();
    	var time  = $("#chooseTime").val();
    	if(time == "")
    		return;
    	var data = {
    			time:time,
    			geoCode:global_sketch_geoCode,
    			geoCodeType:global_sketch_geoCodeType
    	}
    	$.post("query_sketch.shtml",data,onQueryAllFeaturesCallBack);
    }
    
    function onQueryAllFeaturesCallBack(res){
    	var obj = $.parseJSON(res);
    	if(!global_vector_layer){
    		global_vector_layer = new OpenLayers.Layer.Vector("SketchLayer");
    		map.addLayer(global_vector_layer);
    	}
    	for(var i=0;i<obj.length; i++){
    		var featureObj = obj[i];
    		var geometryObj = $.parseJSON(featureObj.sketchString);
    		var geometryString = geometryObj.geometry;
    		var type = geometryObj.type;
    		var feature;
    		if(type==0){
    			feature = getPoint(geometryString);
    		}
    		else{
    			feature = getLine(geometryString);
    		}
    		feature.fid=featureObj.id;
    		global_vector_layer.addFeatures([feature]);
    	}
    }
    
    function getLine(geometryString){
    	var xys = geometryString.split(',');
    	var pntList = new Array();
    	for(var i=0;i<xys.length;i++){
    		if(i%2==0){
    			var x= parseFloat(xys[i]);
        		var y = parseFloat(xys[i+1]);
        		var pt = top.lonLat2Mercator(x,y);
        		var pnt = new OpenLayers.Geometry.Point(pt.x,pt.y);
        		pntList.push(pnt);
    		}
    	}
    	var line =  new OpenLayers.Geometry.LineString(pntList);
    	return new OpenLayers.Feature.Vector(line,null,null);
    }
    
    function getPoint(geometryString){
    	var xys = geometryString.split(',');
    	var x= parseFloat(xys[0]);
		var y = parseFloat(xys[1]);
		var pt = top.lonLat2Mercator(x,y);
        var point = new OpenLayers.Geometry.Point(pt.x,pt.y);
        var pointFeature = new OpenLayers.Feature.Vector(point,null,null);
        return pointFeature;
    }
    
    
function onSketchQueryDlgMin(){
	minDlgByAnimate(sketchQueryDlg);
}

function onSketchQueryDlgClose(){
	if(global_vector_layer)
	{
		global_vector_layer.removeAllFeatures();
		global_vector_layer =null;
	}
	sketchQueryDlg =null;
}
